<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<title></title>
<style>
	body{
		text-align: center;
	}
</style>
</head>
<body background="../img/dahai.jpg">
	<h1>用户注册</h1>
	账号：<input type="text" id="username" placeholder="请输入您的账号"><br><br>
	密码：<input type="text" id="password" placeholder="请输入您的密码"><br><br>
	性别：<select id="sex">
		<option value="男" selected="selected">男</option>
		<option value="女">女</option>
	</select>&nbsp;<br><br>
	<button style="width: 150px;height: 30px;">注册</button>
	
	
	<script>
		url='http://127.0.0.1:8000';
		
		
		$('#username').blur(function(){
			//console.log($(this))
			var stu={username:$(this).val()};
			$.get(url+'/find',stu,function(data){
				console.log(data);
				data.body[0].length ? alert('已经存在该用户，禁止重复'):null
				
			})
			
		})
		$('button').click(function(){
			var stu={
				username:$('#username').val(),
				password:$('#password').val(),
				sex:$('option:selected').val()
				
			}
			$.post(url+'/register',stu,function(data){
				console.log(data);
				data.success ? alert('注册成功'):alert('注册失败')
				
				
			})
		
			
			
			
		})
		// console.log(data);
		
		// if(data.body.length){
		// 	alert('已经存在该用户，禁止重复')
		
	</script>
</body>
</html>
